package com.itheima.controller;

import com.itheima.doamin.Student;
import com.itheima.factory.Factory;
import com.itheima.service.Iservice;

import java.util.ArrayList;
import java.util.Scanner;

public class ControlerImpl implements IController {
    private Iservice iservice = Factory.getService();
    private Scanner sc = new Scanner(System.in);


    @Override
    public void addStudent() {
        String id = sc.next();
        String name = sc.next();
        Student student = new Student(id, name);
        iservice.addStudent(student);
    }

    @Override
    public void deleteStudentById() {
        String id = sc.next();
        iservice.deleteStudentById(id);
    }

    @Override
    public void updateStudent() {
        String id = sc.next();
        String name = sc.next();
        Student student = new Student(id, name);
        iservice.updateStudent(id, student);
    }

    @Override
    public void findAllStudents() {
        ArrayList<Student> allStudents = iservice.findAllStudents();
        for (int i = 0; i < allStudents.size(); i++) {
            System.out.println(allStudents.get(i));
        }
    }
}
